import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
import org.apache.lucene.store.RAMDirectory;
import org.wltea.analyzer.lucene.IKAnalyzer;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/******************************************************************************
 * @Package: [PACKAGE_NAME.Main]
 * @ClassName: [Main]
 * @Description: [一句话描述该类的功能]
 * @Author: [fengli@founder.com.cn]  
 * @CreateDate: [2018/12/24 10:11]   
 * @UpdateUser: [fengli@founder.com.cn (如多次修改保留历史记录，增加修改记录)]   
 * @UpdateDate: [2018/12/24 10:11，(如多次修改保留历史记录，增加修改记录)]   
 * @UpdateRemark: [说明本次修改内容, (如多次修改保留历史记录 ， 增加修改记录)]
 * @Version: [v1.0]
 * ${tags}
 */
public class Main {
    private static Map<String,String> marks=new HashMap<String, String>();
    static {
        marks.put("11278321", "标准地址综合查询");
        marks.put("11135789", "实有房屋管理");
        marks.put("11135982", "巡逻盘查");
        marks.put("11135983", "卡口管理");

        marks.put("11135997", "警务日志");
        marks.put("11136090", "消息通知");
        marks.put("11136091", "通知通报");
        marks.put("11140562", "工作中发现案件");
    }

    public static void main(String argc[]) throws IOException {
        RAMDirectory ramDirectory= IndexManagerUtils.createIndextIntoRAM(marks);
        Map<String,String> result= IndexManagerUtils.serachByStr("通知", ramDirectory);
        for(String key:result.keySet()){
            System.out.println("id:"+key+"     label:"+result.get(key));
        }
    }
    public void tokenTest() {
        Analyzer analyzer = new IKAnalyzer();
        String words = "中华人民共和国";
        TokenStream stream = null;

        try {
            stream = analyzer.tokenStream("myfield", words);
            stream.reset();
            CharTermAttribute offsetAtt = stream.addAttribute(CharTermAttribute.class);
            while (stream.incrementToken()) {
                System.out.println(offsetAtt.toString());
            }
            stream.end();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }finally{
            try {
                stream.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }


}
